<?php


namespace app\common\model;

use think\Model;

/**
 * 车辆库存日历
 * Class CarrRepertoryCalendar
 * @package app\common\model
 */
class CarRepertoryCalendar extends Model
{
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = 'update_time';
    // 追加属性
    protected $append = [
    ];

    /**
     * 获取时间段内的车辆的剩余库存
     * @param string $startDate
     * @param string $endDate
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getCarRepertoryByTime($startDate, $endDate)
    {
        if ($startDate == '' || $endDate == '') {
            return [];
        }
        $where = " date(calendar) >= '{$startDate}' and  date(calendar) <= '{$endDate}' and remain_repertory = 0 ";
        $data =  self::where($where)->distinct('car_id')->column('car_id');
//        var_dump($data);
        return $data;
    }


}
